// packageD/mycomponent/sharePoster/sharePoster.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {

  }
})
// packageH/deposit_group/component/sharePoster/sharePoster.js  ../../../../poster/poster.js
var posterBehavior = require("../../../poster/poster");
var app = getApp();

Component({
  behaviors: [posterBehavior],
  properties: {
    urlapi: {
      type: null
    },
    activityid: {
      type: null,
    }
  },

  data: {},
  ready() {
    // this.getPosterPic();
  },

  /**
   * 组件的方法列表
   */
  methods: {
    async getPosterPic() {
      var urlStr = app.getNetAddresss(this.properties.urlapi);
      wx.showLoading({
        title: '加载中',
      });
      app._getNetWork({
        url: urlStr,
        // 需要修改参数
        data: {id: this.properties.activityid},
        success: (resdata) => {
          wx.hideLoading();
          let res = resdata.data;
          if (res.result != 1) {
            wx.showModal({
              title: '提示',
              content: res.msg,
              showCancel: false,
              success: (res)=> {
                if (res.confirm) {
                  this.setData({isshow: false,getFlag: true})
                }
              }
            })
            return;
          }
          this.setData({
            poster: res.data.poster,
          });
        },
        fail () {
          wx.hideLoading();
        }
      });
    },
    saveImg() {
      var imgSrc = this.data.poster;
      var imgPath =
        wx.env.USER_DATA_PATH + "/solitaire_qrcode" + "haibao" + ".png";
      var imageData = imgSrc.replace(/^data:image\/\w+;base64,/, "");
      var fs = wx.getFileSystemManager();
      fs.writeFileSync(imgPath, imageData, "base64");
      wx.saveImageToPhotosAlbum({
        filePath: imgPath,
        success: (data) => {
          fs.unlinkSync(imgPath);
          wx.showToast({
            title: "保存成功",
            icon: "none",
            duration: 2000,
          });
        },
        fail: function (err) {
          console.log(err);
        },
      });
    },
  },
});
